import { get, post } from '@/utils/request.js'
import Config from '@/config'
import dayjs from 'dayjs'

export default {
  getClientOrg(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetConfigurationItemList', {
      clientOrgID: id
    })
  },
  saveClientOrg(id, org) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/UpdateConfigurationItem', {
      hrOrgIds: org,
      clientOrgID: id
    })
  },
  getBlacklistStatus(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetBlackOnOff', {
      clientOrgID: id
    })
  },
  getBlacklistedReason(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetClientBlackList', { clientID: id })
  },
  addClintToBlackList(id, reason) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/AddClientBlackList', {
      clientID: id,
      reason: reason
    })
  },
  revokeBlacklistRecord(clientId, recordId, reason) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/UpdateBlackList', {
      id: recordId,
      clientID: clientId,
      reason: reason
    })
  },
  getOperateRecords(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetBlackHistroryList', {
      clientOrgID: id
    })
  },
  getSatisfactionSurveyStatus(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetSurveySwitchOnOff', {
      clientOrgID: id
    })
  },
  saveSatisfactionSurveyStatus(id, status, month) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/UpdateSurveySwitch', {
      clientOrgID: id,
      surveySwitch: status,
      surveyMonth: month
    })
  },
  getAccountManagerCandidates(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetAMSearchUserList', { clientOrgID: id })
  },
  getAccountManagers(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetAMUserList', {
      clientOrgID: id
    })
  },
  addAccountManager(id, userId) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/AddAMUser', {
      clientID: id,
      amid: userId
    })
  },
  deleteAccountManager(id, userId) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/DeleteAMUser', {
      clientID: id,
      amid: userId
    })
  },
  getProjectManagerCandidates(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetPMSearchUserList', { clientOrgID: id })
  },
  getProjectManagers(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetPMUserList', {
      clientOrgID: id
    })
  },
  addProjectManager(id, userId) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/AddPMUser', {
      clientID: id,
      pmid: userId
    })
  },
  deleteProjectManager(id, userId) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/DeletePMUser', {
      clientID: id,
      pmid: userId
    })
  },
  setProjectManagerPrincipal(id, userId) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/SetPMUserPrincipal', {
      clientID: id,
      pmid: userId
    })
  },
  // 获取可添加的候选人列表
  getSalesCandidatesList(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetSalesSearchUserList', { clientOrgID: id })
  },
  getSalesList(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetSalesUserList', { clientOrgID: id })
  },
  saveSalesPerson(id, data) {
    if (!data.id) {
      return post(Config.API_VERSION + '/TargetClients/Configuration/AddSalesUser', {
        clientId: id,
        personId: data.personId,
        salesRule: data.percentage / 100,
        firstProjectDate: data.date
      })
    } else {
      return post(Config.API_VERSION + '/TargetClients/Configuration/UpdateSalesUser', {
        clientId: id,
        id: data.id,
        personId: data.personId,
        salesRule: data.percentage / 100,
        firstProjectDate: data.date
      })
    }
  },
  deleteSalesPerson(salesID) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/DeleteSalesUser', { salesID: salesID })
  },
  saveBeginCooperate(id, data) {
    return post(Config.API_VERSION + '/TargetClients/Configuration/RenewBeginCooperate', {
      id: id,
      beginCooperate: data.type === 2 ? dayjs(data.date).format('YYYY-MM-DD') : null,
      reason: data.reason
    })
  },
  loadBeginCooperateInfo(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetBeginCooperate', {
      clientOrgID: id
    })
  },
  getWiitransAccountInfo(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetWiitransAccount', {
      clientOrgID: id
    })
  },
  setWiitransAccountInfo(id, account) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/SetWiitransAccount', {
      clientOrgID: id,
      account: account
    })
  },
  getAllowDownloadInvoiceFileStatus(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/GetClientDownloadInvoiceFile', { clientOrgID: id })
  },
  changeAllowDownloadInvoiceFileStatus(id) {
    return get(Config.API_VERSION + '/TargetClients/Configuration/SetClientDownloadInvoiceFile', { clientOrgID: id })
  }
}
